<template>
	<view class="container review">
		<view v-if="ascription=='3'">
			<view class="true_sticky"><v-tabhead @barTap="barTap" :headItems="headItems" :activeIndex="activeIndex"></v-tabhead></view>
			<swiper :current="activeIndex" @change="changeTab" class="homeSwiperContainer">
				<swiper-item v-for="(item, index) in headItems" :key="index">
					<true-topic-data :ascription="ascription" :homeCode="homeCode" :code="item.code"></true-topic-data>
				</swiper-item>
			</swiper>
		</view>
		<view v-if="ascription=='2'">
			<swiper class="homeSwiperContainer">
				<swiper-item>
					<true-topic-data :ascription="ascription" :homeCode="homeCode" :code="homeCode"></true-topic-data>
				</swiper-item>
			</swiper>
		</view>
		
	</view>
</template>

<script>


import trueTopicData from './fragment/true_topic_data';
import VTabhead from './fragment/vtabhead/index';

export default {
	data() {
		return {
			ascription:undefined,
			headItems: [
				{
					label: '公安联考',
					code: 0
				},
				{
					label: '全国社招',
					code: 1
				},
				{
					label: '地方社招',
					code: 2
				}
			],
			activeIndex: 0,
			indexs:0
		};
	},
	computed: {
		homeCode(){
			if(this.ascription==3){
				if(this.headItems.length==0) return '';
				const code = this.headItems[this.activeIndex].code;
				// console.log(code);
				return this.headItems[this.activeIndex].code;
			}else{
				return 4;
			}
		}
	},
	components: {
		VTabhead,
		trueTopicData
	},
	onLoad(query) {
		this.ascription = query.ascription;
		uni.$on('examFinish', (payload) => {
				console.log('pages examFinish',this.code,payload);
				//this.updateItemStatus(payload);
			})
	},
	//点击历史答题
	onNavigationBarButtonTap() {
		uni.navigateTo({
			url: "/pages/exam/history?ascription="+this.ascription
				+"&examType=1&resultType=4"
		})
	},
	methods: {
		barTap(activeIndex) {
			this.activeIndex = activeIndex;
		},
		changeTab(e) {
			let index = e.target.current;
			this.activeIndex = index;
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f1f1f1;
}
.containerin {
	background-color: #fff;
}

.homeSwiperContainer {
	width: 100%;
	height: calc(100vh - 30px);
	flex: 1;
}
.review {
	display: flex;
	flex-direction: column;
}
// .true_sticky {
// 	position: sticky;
// 	top: 0;
// 	z-index: 80;
// 	/*当menu元素距离可视窗口顶部<0时，menu由sticky定位切换为fixed定位*/
// }
</style>
